#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'测试XML读取数据'
from xml.parsers.expat import ParserCreate

class ParseXMLHandler(object):
    def start_element(self, name, attrs):
        print('sax:start_element:%s,attrs:%s' % (name, str(attrs)))

    def char_data(self, text):
        print('sax:char_data:%s' % (text))

    def end_element(self, name):
        print('sax:end_element:%s' % (name))


handler = ParseXMLHandler()
parser = ParserCreate()
parser.StartElementHandler = handler.start_element
parser.CharacterDataHandler = handler.char_data
parser.EndElementHandler = handler.end_element


with open('123.xml','rb') as f:
    for line in f:
        parser.Parse(line)

